package com.aabte.design2.behavioral.iterator;

import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;

import java.util.Collection;
import java.util.Collections;

/**
 * 微信
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
public class WeChat implements SocialNetwork {

    private static final Multimap<Integer, Profile> FRIENDS = LinkedHashMultimap.create();
    private static final Multimap<Integer, Profile> COWORKERS = LinkedHashMultimap.create();

    static {
        FRIENDS.put(1, new Profile(1));
        FRIENDS.put(1, new Profile(2));
        FRIENDS.put(1, new Profile(3));
        FRIENDS.put(1, new Profile(4));
        FRIENDS.put(1, new Profile(5));

        COWORKERS.put(1, new Profile(1));
        COWORKERS.put(1, new Profile(2));
        COWORKERS.put(1, new Profile(3));
        COWORKERS.put(1, new Profile(4));
        COWORKERS.put(1, new Profile(5));
    }

    @Override
    public ProfileIterator createFriendsIterator(int profileId) {
        return new WeChatIterator(this, profileId, "friends");
    }

    @Override
    public ProfileIterator createCoworkersIterator(int profileId) {
        return new WeChatIterator(this, profileId, "coworkers");
    }

    public Collection<Profile> socialGraphRequest(int profileId, String type) {
        if ("friends".equals(type)) {
            return FRIENDS.get(profileId);
        }
        if ("coworkers".equals(type)) {
            return COWORKERS.get(profileId);
        }
        return Collections.emptyList();
    }
}
